Imports System.Collections

Partial Class pages_emailtemplates_usercontrols_UCEmailTemplate : Inherits UserControl

#Region "Members"
    Private m_emailTemplate As CEmailTemplate
    Private m_sortedList As IList
#End Region

#Region "Interface"
    Public Sub Display(ByVal [emailTemplate] As CEmailTemplate, sortedList As IList, showSubject As Boolean)
        If Parent.Controls.Count Mod 2 = 0 Then row.Attributes.Add("class", "alt_row")

        m_emailTemplate = [emailTemplate]
        m_sortedList = sortedList
        colAdmin.Visible = CSession.IsDeveloper
        colSubject.Visible = showSubject

        With m_emailTemplate
            litNumber.Text = CStr(sortedList.IndexOf(m_emailTemplate) + 1)
            lnkTemplateName.Text = CStr(IIf(.TemplateName.Length = 0, "...", .TemplateName))
            lnkTemplateName.NavigateUrl = CSitemap.EmailTemplateEdit(.TemplateId)
            litTemplateSubject.Text = CUtilities.Truncate(.TemplateSubject, 50)
            litTemplateSubject.ToolTip = .TemplateSubject
            litTemplateBody.Text = CUtilities.FileSize(.TemplateBody.Length)

            Dim list As List(Of String) = CUtilities.StringToListStr(.TemplateTags)
            litTemplateTags.Text = CUtilities.CountSummary(list, "tag", "none")
            If list.Count > 0 Then litTemplateTags.ToolTip = String.Concat("[", CUtilities.ListToString(list, String.Concat("]", vbCrLf, "[")), "]")
        End With
    End Sub
#End Region

#Region "Event Handlers"
    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDelete.Click
        m_emailTemplate.Delete()
        Refresh()
    End Sub
#End Region

#Region "Private"
    Private Sub Refresh()
        'CCache.ClearCache()

        'If False Then 'Request.RawUrl.ToLower.Contains("myparent.aspx") Then
        '    'Special case: Parent entity owns the list
        '    Response.Redirect(CSitemap.MyParentEdit(m_emailTemplate.EmailTemplateParentId, MyParent.ETab.emailtemplates, m_pageIndex)
        'Else
        '    'Normal case: Search page owns the list
            Response.Redirect(Request.RawUrl) 'includes paging info
        'End If 
    End Sub
#End Region

End Class
